/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.img;

import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Positions;

import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * <p>Project: app2022 - ThumbnailatorDemo1
 * <p>Powered by webrx On 2022-01-24 17:58:52
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ThumbnailatorDemo1 {
    public static void main(String[] args) throws IOException {
        //1. 对图片进行指定尺寸压缩，（缩略图）
        //Thumbnails.of("D:\\download\\pic\\pok.jpg").size(300, 300).toFile("p23ok.jpg");

        //2. 对图片按比例生成缩略图
        //Thumbnails.of("p.jpg").scale(.5).toFile("p5.jpg");

        //3. 旋转图片
        //Thumbnails.of("office.jpg").scale(.8).rotate(-45).toFile("office8_90.jpg");

        //4. 格式转换 git jpg png webp(新格式)
        //Thumbnails.of("office.jpg").scale(1f).outputFormat("gif").toFile("o.gif");

        //5 剪裁
        //Thumbnails.of("office.jpg").scale(1.0).sourceRegion(0, 0, 100, 100).toFile("o_100_100.jpg");

        //6 水印效果 水印图标
        //var logo = ImageIO.read(new File("logo.png"));
        //Thumbnails.of("p.jpg").scale(1.0).watermark(Positions.CENTER, logo, .5f).toFile("p_logo.jpg");

        //水印文字
        var i = new BufferedImage(100, 80, 2);
        var g = i.createGraphics();
        g.drawString("hello world", 10, 35);
        g.dispose();
        //"p.jpg" String   scale(double float) watermarker(
        Thumbnails.of("p.jpg").scale(1.0).watermark(Positions.CENTER, i, 1f).toFile("p_logo.jpg");


    }
}
